package com.zmn.oms.services.impl.review;

import com.zmn.common.utils.collection.CollectionUtil;
import com.zmn.common.utils.date.DateUtil;
import com.zmn.oms.model.entity.review.OmsOrderReview;
import com.zmn.oms.model.entity.review.OrderReviewDbQuery;
import com.zmn.oms.persistence.interfaces.review.OmsOrderReviewDao;
import com.zmn.oms.services.interfaces.review.OmsOrderReviewService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * @ClassName OmsOrderReviewService
 * @description:
 * @author: wangyanci
 * @create: 2021-08-06 17:15
 * @Version 1.0
 **/
@Slf4j
@Service
public class OmsOrderReviewServiceImpl implements OmsOrderReviewService {

    @Resource
    private OmsOrderReviewDao orderReviewDao;

    public OmsOrderReview getOmsOrderReviewById(@NonNull Long reviewId, @NonNull Long orderId) {
        return orderReviewDao.findOmsOrderReviewByKey(reviewId, orderId);
    }

    @Override
    public OmsOrderReview getOmsOrderReviewByOrderIdAndWorkIdAndType(@NonNull Long orderId, @NonNull Long workId, @NonNull Integer reviewType) {
        return orderReviewDao.findOmsOrderReviewByOrderIdAndWorkIdAndType(orderId, workId, reviewType);
    }

    @Override
    public OmsOrderReview getOmsOrderReviewByQuery(OrderReviewDbQuery query) {
        return orderReviewDao.findOmsOrderReviewByQuery(query);
    }

    @Override
    public int insertOmsOrderReview(OmsOrderReview omsOrderReview) {
        return orderReviewDao.insertOmsOrderReview(omsOrderReview);
    }

    @Override
    public int updateById(OmsOrderReview omsOrderReview) {
        Objects.requireNonNull(omsOrderReview.getOrderId());
        return orderReviewDao.updateByPrimaryKeySelective(omsOrderReview);
    }

    @Override
    public List<OmsOrderReview> getOmsOrderReviewByOrderIdsAndType(List<Long> orderIds, int omsOrderReviewRefund) {
        if (CollectionUtil.isNullOrEmpty(orderIds)) {
            return null;
        }
        return orderReviewDao.getOmsOrderReviewByOrderIdsAndType(orderIds, omsOrderReviewRefund);
    }

    @Override
    public List<OmsOrderReview> listOrderReviewByOrderIdList(List<Long> orderIdList) {
        if (CollectionUtil.isNullOrEmpty(orderIdList)) {
            return null;
        }
        return orderReviewDao.listOrderReviewByOrderIdList(orderIdList);
    }

    @Override
    public void deleteById(OmsOrderReview deleteOrderReview) {
        orderReviewDao.deleteById(deleteOrderReview);
    }
}
